export default {
    data() {
        return {
            currImageLayer: ''
        }
    },
    mounted() {
        this.lastImageLayer = null
        this.$nextTick(() => {
            this.creatDOM()
        })
    },
    methods: {
        clearDOMOL() {
            if (this.imageLayerDOMLP) this.imageLayerDOMLP.show = false
            if (this.imageLayerDOMSJ) this.imageLayerDOMSJ.show = false
            if (this.imageLayerDOMOL) this.imageLayerDOMOL.show = false
        },
        creatDOMOL() {

        },
        creatDOM() {
            this.addAcrGis()
            // this.addSuper()
            // this.creatDOMLP()
            var eventFn = (level) => {
                // console.log(this.imageLayerDOMLP)
                if (!this.imageLayerDOMOL || !this.imageLayerDOMSJ || !this.imageLayerDOMLP) return
                // console.log(level)
                // console.log(this.$viewer.imageryLayers)
                if (this.layerList2[0].children.DOMOL.show) {
                    this.imageLayerDOMOL.show = level >= 10000
                    this.imageLayerDOMSJ.show = level >= 100
                    this.imageLayerDOMLP.show = level <= 500
                } else {
                    this.imageLayerDOMOL.show = false
                    this.imageLayerDOMSJ.show = false
                    this.imageLayerDOMLP.show = false
                }
            }
            this.$store.getters.eventCesiumOption.levelFns.set('影像切换', eventFn)
        },

        addAcrGis() {
            // var imageryProvider = new Cesium.ArcGisMapServerImageryProvider({
            //     url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
            //     enablePickFeatures: false
            // })
            // this.imageLayerDOMOL = this.$viewer.imageryLayers.addImageryProvider(imageryProvider)
            var tilingScheme = new Cesium.GeographicTilingScheme({
                ellipsoid: Cesium.Ellipsoid.WGS84, // 设置椭球体为 WGS84
                numberOfLevelZeroTilesX : 1,
                numberOfLevelZeroTilesY : 1,
                rectangle : new Cesium.Rectangle(
                    Cesium.Math.toRadians(-180.0),
                    Cesium.Math.toRadians(-270.0),
                    Cesium.Math.toRadians(180.0),
                    Cesium.Math.toRadians(90.0)
                )
            });
            var imageryProvider = new Cesium.WebMapTileServiceImageryProvider({
                url: 'https://fxpc.mem.gov.cn/data_preparation/08646ad0-dc4c-43c0-ac82-c8fb76a6ad4a/0f6a780d-6a6c-41ff-a8c2-61b498945fb8/wmts',
                service: 'wmts',
                request: 'gettile',
                version: '1.0.0',
                layer: 'img',
                style: 'default',
                format: 'tiles',
                tileMatrixSetID: 'c',
                geokey: 'B35E9A521D593C24D6605B275A0111CE',
                maximumLevel: 20, // 设置最大级别，根据实际情况进行调整
                credit: 'Data Source: fxpc.mem.gov.cn', // 数据来源注释，可选
                tilingScheme: tilingScheme,
            })
            this.imageLayerDOMLP = this.$viewer.imageryLayers.addImageryProvider(imageryProvider);
        },
        //正射影像
        creatDOMLP() {
            var tileUrlPre = `${mapConfig.tileUrlPre}/image/wmts/0d7iNkJJ/{z}/{x}/{y}`
            console.log(tileUrlPre)
            var rect;
            rect = Cesium.Rectangle.fromRadians(1.9994617027026291, 
                0.42553895549121834, 
                2.000198785648579, 
                0.4277467894373245)
            var imageryProvider = new Cesium.UrlTemplateImageryProvider({
                // url: '/mapData/guangdong/JWD256/{z}/{x}/{y}.png',
                url: tileUrlPre,
                tilingScheme: new Cesium.WebMercatorTilingScheme(), // WebMercatorTilingScheme //GeographicTilingScheme
                rectangle: rect,
                fileExtension: 'png',
                minimumLevel: 0,
                maximumLevel: 20
            })
            this.imageLayerDOMLP = this.$viewer.imageryLayers.addImageryProvider(imageryProvider)
        },
        addSuper() {
            var url = 'http://183.6.105.178:6088/terrain/ArLpWlxO/layer'
            // var url = '/DOM/meta'
            this.$axios.get(url + '.json').then(res => {
                console.log(res.data)
                var scales84 = [3.38032714321E-9, 6.76065428641E-9, 1.352130857282E-8, 2.704261714564E-8, 5.408523429128E-8,
                    1.0817046858257E-7, 2.1634093716514E-7, 4.3268187433028E-7, 8.6536374866056E-7, 1.73072749732112E-6,
                    3.46145499464224E-6, 6.92290998928448E-6, 1.3845819978568952E-5, 2.7691639957137904E-5,
                    5.538327991427581E-5, 1.1076655982855162E-4, 2.2153311965710323E-4, 4.4306623931420646E-4,
                    8.861324786284129E-4, 0.0017722649572568258, 0.0035445299145136517, 0.007089059829027303
                ]

                var scalesweb = [1.69016357160E-9, 3.38032714321E-9, 6.76065428641E-9, 1.352130857282E-8, 2.704261714564E-8,
                    5.408523429128E-8, 1.0817046858257E-7, 2.1634093716514E-7, 4.3268187433028E-7, 8.6536374866056E-7,
                    1.73072749732112E-6, 3.46145499464224E-6, 6.92290998928448E-6, 1.3845819978568952E-5,
                    2.7691639957137904E-5, 5.538327991427581E-5, 1.1076655982855162E-4, 2.2153311965710323E-4,
                    4.4306623931420646E-4, 8.861324786284129E-4, 0.0017722649572568258, 0.0035445299145136517,
                    0.007089059829027303
                ]
                var name = res.data.name
                // var rectangle = Cesium.Rectangle.fromDegrees(result.bounds.left, result.bounds.bottom, result.bounds.right, result.bounds.top)
                var rectangle = Cesium.Rectangle.fromDegrees(-180, -90, 180, 90)
                var epsgcode = res.data.projection
                var tilingScheme = ''
                var minlevel = 0
                var maxlevel = 17
                var originx = 0
                var originy = 0
                if (epsgcode === 'EPSG:4326') {
                    tilingScheme = new Cesium.GeographicTilingScheme({
                        numberOfLevelZeroTilesX: 2,
                        numberOfLevelZeroTilesY: 1
                    })
                    originx = -180
                    originy = 90
                }
                if (epsgcode === 3857) {
                    tilingScheme = new Cesium.WebMercatorTilingScheme()
                    originx = -20037508.34
                    originy = 20037508.34
                }

                var layerProvider = new Cesium.UrlTemplateImageryProvider({
                    url: url +
                        "/tileImage.png?transparent=true&cacheEnabled=true&width=256&height=256&x={x}&y={y}&scale={scale}&redirect=false&overlapDisplayed=false&origin={'x':" +
                        originx + ",'y':" + originy + '}',
                    rectangle: rectangle,
                    minimumLevel: minlevel || 0,
                    maximumLevel: maxlevel || 22,
                    tilingScheme: tilingScheme,
                    customTags: {
                        scale: function (imageryProvider, x, y, level) {
                            if (epsgcode === 4326) {
                                return scales84[level]
                            }
                            if (epsgcode === 3857) {
                                return scalesweb[level]
                            }
                        }
                    }
                })
                this.imageLayerDOMSJ = this.$viewer.imageryLayers.addImageryProvider(layerProvider, 1)
            })
        },
        addTDT() {
            var tiandituTk = '6f2afe410bfcae554dee49b9127a6c84'
            var subdomains = ['0', '1', '2', '3', '4', '5', '6', '7']
            var imageryProvider = new Cesium.WebMapTileServiceImageryProvider({
                // 影像底图
                url: 'http://t{s}.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=' +
                    tiandituTk,
                subdomains: subdomains,
                layer: 'tdtBasicLayer',
                style: 'default',
                format: 'image/jpeg',
                tileMatrixSetID: 'GoogleMapsCompatible', // 使用谷歌的瓦片切片方式
                maximumLevel: 18,
                show: true
            })
            this.imageLayerDOMOL = this.$viewer.imageryLayers.addImageryProvider(imageryProvider, 1)
        }
    }
}
